<template>
  <h1>我是登录页面</h1>
  <div>
    <p>账号: <input type="text" v-model.trim="user.username"></p>
    <p>密码: <input type="text" v-model.trim="user.password"></p>
    <p>
      <button @click="logined">登录</button>
    </p>
  </div>
</template>

<script>


export default {
  name: "login.vue",
  data() {
    return {
      user: {
        username: "yykk",
        password: "123456"
      }
    }
  },
  methods: {

    // ...mapActions("user",{
    //   logined(dispatch) {
    //     // 1、获取用户名和密码
    //     let {username,password} = this.user;
    //     let promise = dispatch("logined",{username,password});
    //     promise.then(()=>{
    //       let address = localStorage.getItem("gotoAddreess");
    //       this.$router.push(address || "/");
    //     }).catch(res=>{
    //       if (res.data.status== 101100601){
    //         alert("用户名或者密码输入有误");
    //       }
    //     })
    //   }
    // }),

    logined() {
        // 1、获取用户名和密码
      let {username,password} = this.user;
      let promise = this.$store.dispatch("user/logined",{username,password});
      promise.then(()=>{
        let address = localStorage.getItem("gotoAddreess");
        this.$router.push(address || "/");
      }).catch(res=>{
        if (res.data.status== 101100601){
          alert("用户名或者密码输入有误");
        }
      })
    }
  }
}
</script>

<style scoped>

</style>